package com.hdu.dwh.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.support.RestClientAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;

import com.hdu.dwh.service.SupersetRestService;
@Configuration
public class SupersetRestConfig {
    @Value("${dwh.superset.base-url}")
    private String supersetBaseUrl;

    @Bean
    public SupersetRestService supersetRestService() {
        RestClient restClient = RestClient.builder()
                .baseUrl(supersetBaseUrl)
                .defaultHeader(HttpHeaders.COOKIE, "")
                .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
                .build();
        RestClientAdapter adapter = RestClientAdapter.create(restClient);
        HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(adapter)
                .build();
        return factory.createClient(SupersetRestService.class);
    }

}
